package com.twu.biblioteca;
import org.omg.CORBA.PUBLIC_MEMBER;

import java.util.Scanner;

/**
 * Created by mauricio on 10/2/14.
 */
public class UserController {

    public void loginAction() {
        System.out.println("\n---- LOGIN ----");

        collectUserCredentials();

        while(!Auth.isLogged()) {
            System.out.println("\nLibrary Number or password incorrect!");
            collectUserCredentials();
        }

        // With Success Login
        System.out.println();
        FlashMessage flashMessage = new FlashMessage();
        System.out.println("Hello "+ Auth.getLoggedUser().getName());
        System.out.println(flashMessage.getGreetingMessage());



    }

    public void showAction() {
        User user = Auth.getLoggedUser();
        System.out.println("Name: " + user.getName());
        System.out.println("Email: " + user.getEmail());
        System.out.println("Phone: " + user.getPhone());
    }

    private void collectUserCredentials() {
        System.out.print("\nLibrary Number: ");
        String libraryNumber = new Scanner(System.in).nextLine();
        System.out.print("Password: ");
        String password = new Scanner(System.in).nextLine();

        Auth.authenticate(libraryNumber, password);




    }


}
